package io.renren.modules.dishes.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.R;
import io.renren.modules.dishes.entity.CommoditySkuEntity;
import io.renren.modules.dishes.service.skuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.WeakHashMap;

@RestController
@RequestMapping("/web/sku")
public class skuController {

    @Autowired
    private skuService skuService;
    @GetMapping("/list/{spuId}")
    public R getList(@PathVariable("spuId") String spuId){
        List<CommoditySkuEntity> list = skuService.getList(spuId);
        return R.ok().put("list",list);
    }

    @PostMapping("/save")
    public R saveSku(@RequestBody CommoditySkuEntity sku){
        Boolean Boolean = skuService.saveSku(sku);
        if (Boolean){
            return R.ok();
        }else {
            return R.error("已有该规格");
        }
    }

    @PostMapping("/update")
    public R updateSku(@RequestBody CommoditySkuEntity sku){
        Boolean Boolean = skuService.updateSku(sku);
        if (Boolean){
            return R.ok();
        }else {
            return R.error("不能有重复的规格");
        }
    }

    @GetMapping("/get/{skuId}")
    public R get(@PathVariable("skuId") String skuId){
        CommoditySkuEntity one = skuService.get(skuId);
        return R.ok().put("sku",one);
    }

    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable("id") String id){
        skuService.removeById(id);
        return R.ok();
    }



}
